import axios from "./config";
import { canceltoken } from "./config";
//登入接口
const loginapi = (username, password) =>
  axios({
    url: "/users/login",
    method: "post",
    data: {
      username: username,
      password: password,
    },
    /* headers:{
        'content-type':"application/json"
    } */
  });
//获取验证码接口
const getCaptcatapi = () =>
  axios({
    url: "/users/getCaptcha",
    method: "GET",
  });
//校验验证码接口
const verifyCaptchaapi = (captcha) =>
  axios({
    url: "/users/verifyCaptcha",
    method: "get",
    params: {
      captcha: captcha,
    },
  });
//获取登录日志接口
const getloginlog = (components, pages = 1, count = 15) =>
  axios({
    cancelToken: new canceltoken((c) => {
      //c这个方法可以绑定给组件实例，然后调用此方法取消请求
      components.canceltoken = c;
      // console.log(components);
    }),
    url: "/getloginlog",
    method: "get",
    params: {
      pages: pages,
      count: count,
    },
  });

//微信登入api
const wechatapi = (wechatCode) =>
  axios({
    url: "/users/wechatLogin",
    method: "get",
    params: {
      wechatCode: wechatCode,
    },
  });
//获取微信二维码地址
const getwechatqrcode = (sid) =>
  axios({
    url: "/users/getQrcode",
    method: "get",
    params: {
      sid: sid,
    },
  });

//获取权限菜单
const getMenulist = () =>
  axios({
    url: "/permission/getMenuList",
    method: "get",
  });
//获取学员项目表格数据
const getstudata = (page = 1, count = 15, classes = "") =>
  axios({
    url: "/students/getstulist",
    method: "get",
    params: {
      page: page,
      count: count,
      class: classes,
    },
  });

//增加学员信息
const addstuinfo = (data) =>
  axios({
    url: "/students/addstu",
    method: "post",
    data: data,
  });
//修改学员信息
const updatestuinfo = (data) =>
  axios({
    url: "/students/updatestu",
    method: "post",
    data: data,
  });

//删除学员信息
const deletestuinfo = (sId) =>
  axios({
    url: "/students/delstu",
    method: "get",
    params: {
      sId: sId,
    },
  });
//获取班级列表
const getclasslist = () =>
  axios({
    url: "/students/getclasses",
    method: "get",
  });

//搜索学员
const searchstu = (key = "", count = 10, page = 1) =>
  axios({
    url: "/students/searchstu",
    method: "get",
    params: {
      key: key,
      count: count,
      page: page,
    },
  });
//vip订单
const viporder = (orderid = "") =>
  axios({
    url: "/order/get_order",
    method: "post",
    data: {},
  });
//获取vip产品
const vipproduct = (category_id) =>
  axios({
    url: "/product/get_product",
    method: "get",
    params: {
      category_id: category_id,
    },
  });
//获取预支付订单
const getpreorders = (product_id, quantity) =>
  axios({
    url: "/order/pre_order",
    method: "post",
    data: {
      product_id: product_id,
      quantity: quantity,
    },
  });
//获取订单详情
const getorders = (order_id) =>
  axios({
    url: "/order/get_order",
    method: "post",
    data: {
      order_id: order_id,
    },
  });
//拉起微信二维码支付
const payapi = (order_id) =>
  axios({
    url: "/pay/payment",
    method: "post",
    data: {
      order_id: order_id,
    },
  });
//查询订单支付结果，（这个使用ajax轮询）
const getOrdersState = (order_id) =>
  axios({
    url: "/order/query_order_status",
    method: "get",
    params: {
      order_id: order_id,
    },
  });
export {
  getstudata,
  loginapi,
  getCaptcatapi,
  verifyCaptchaapi,
  getloginlog,
  wechatapi,
  getwechatqrcode,
  getMenulist,
  addstuinfo,
  updatestuinfo,
  deletestuinfo,
  getclasslist,
  searchstu,
  viporder,
  vipproduct,
  getpreorders,
  getorders,
  payapi,
  getOrdersState,
};
